import java.util.ArrayList;
import java.util.List;

public class Test2{
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 给定年份和月份，按照输出当月日历
     * @param year int 年份
     * @param month int 月份(1-12)
     * @param dayOfWeek int 当月1号是星期几，1表示星期一，7表示星期天
     * @return stringArrayList<ArrayList<>>
     */
    public List<List<String>> calendar (int year, int month, int dayOfWeek) {
        List<String> list=new ArrayList<String>();
        int days = days(year, month);
        int l=(dayOfWeek+days-1)/7+1;
        for (int i = 0; i < 7*l; i++) {
            list.add("");
        }

        for (int i = 1; i <= days; i++) {
            list.set(dayOfWeek-2+i,i+"");
        }
        int size=list.size();
        int len=7;
        int count=(size+len-1)/len;
        List<List<String>> res=new ArrayList<>();
        for (int i = 0; i <count ; i++) {
            List<String> subList = list.subList(i * len, (Math.min((i + 1) * len, size)));
            res.add(subList);
        }
        return res;




    }
    public int days(int year,int month){
        int day=0;
        switch (month){
            case 1: case 3: case 5: case 7: case 8: case 10: case 12: day=31;
            break;
            case 4: case 6: case 9: case 11:  day=30;
            break;
            case 2:
                if(year%400==0||year%4==0&&year%100!=0){
                    day=29;
                }else {
                    day=28;
                }
        }
        return day;
    }

    public static void main(String[] args) {
        Test2 test2 = new Test2();
        List<List<String>> calendar = test2.calendar(2021, 4, 4);
        System.out.println(calendar);
    }
}
